<template>
  <a-modal :visible="visible" title="查看" width="50%" :footer="null" @cancel="handleCancel" >
    <div>
      <div class="titleView">
        预算审核
        <div class="state">{{ form.status | enumValueByKey($const.AUDGET_STATUS) }}</div>
      </div>
      <div class="conentView">
        <div class="conentView-item">
          <div class="conentView-item-label">新增金额:</div>
          <div>{{ form.budgetAmount }}</div>
        </div>
        <div class="conentView-item">
          <div class="conentView-item-label">支付日期:</div>
          <div>{{ form.payTime | moment() }}</div>
        </div>
        <div class="conentView-item">
          <div class="conentView-item-label">支付单号:</div>
          <div>{{ form.payNo }}</div>
        </div>
        <div class="conentView-item">
          <div class="conentView-item-label">相关凭证:</div>
          <div>
            <img :src="form.proofUrl | dealImageUrl" style="width:50%">
          </div>
        </div>
        <div class="conentView-item">
          <div class="conentView-item-label">申请人员:</div>
          <div>{{ form.applyNo }}</div>
        </div>
        <div class="conentView-item">
          <div class="conentView-item-label">申请时间:</div>
          <div>{{ form.createTime | moment() }}</div>
        </div>
        <div v-if="!isAudit" class="conentView-item">
          <div class="conentView-item-label">审批人员:</div>
          <div>{{ form.processorNo }}</div>
        </div>
        <div v-if="!isAudit" class="conentView-item">
          <div class="conentView-item-label">审核结果:</div>
          <div>{{ form.status | enumValueByKey($const.AUDGET_STATUS) }}</div>
        </div>
        <div v-if="!isAudit && form.refuseReason" class="conentView-item">
          <div class="conentView-item-label">驳回理由:</div>
          <div>{{ form.refuseReason }}</div>
        </div>
        <div v-if="!isAudit && form.status == 0" class="conentView-item">
          <div class="conentView-item-label">审核状态:</div>
          <div>{{ form.status | enumValueByKey($const.AUDGET_STATUS) }}</div>
        </div>
      </div>
      <div class="bottomView">
        <a-space>
          <a-button
            v-if="!isAudit"
            type="primary"
            @click="handleCancel"
          >
            返回
          </a-button>
          <a-button
            v-if="isAudit"
            type="primary"
            @click="budgetAudit(1,'')"
          >
            确认无误
          </a-button>
          <a-button
            v-if="isAudit"
            type="danger"
            @click="showReufed"
          >
            驳回
          </a-button>
        </a-space>
      </div>
      <a-modal :visible="remarkVisible" title="请输入驳回理由" width="30%" @ok="submitReufed" @cancel="remarkVisible = false" >

        <a-textarea
          v-model="remark"
          placeholder="请输入内容"
          :auto-size="{ minRows: 3}"
        />
      </a-modal>
    </div>
  </a-modal>
</template>
<script>
import { budgetDetail, budgetReview } from '@/api/overview/budget'
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    isAudit: { // 是否是审核
      type: Boolean,
      default: false
    },
    id: {
      type: [Number, String],
      default: 0
    }
  },
  data () {
    return {
      remarkVisible: false,
      remark: '',
      form: {}
    }
  },
  watch: {
    visible (e) {
      if (e) {
        budgetDetail({ id: this.id }).then(res => {
          this.form = res
        })
      }
    }
  },
  methods: {
    budgetAudit (status, refuseReason) {
      budgetReview({
        id: this.id,
        status: status,
        refuseReason: refuseReason
      }).then(res => {
        this.$message.success('审核成功')
        this.handleCancel()
      })
    },
    showReufed () {
      this.remarkVisible = true
      this.remark = ''
    },
    submitReufed () {
      if (!this.remark) {
        this.$message.error('请填写拒绝理由')
        return
      }
      this.budgetAudit(2, this.remark)
    },
    handleCancel () {
      this.$emit('handleCancel')
    }
  }
}
</script>
<style lang="less" scoped>
  .titleView{
    border-left: 5px solid #3d92ff;
    padding-left: 10px;
    font-size: 17px;
    font-weight: 550;
    color: #000;
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    .state{
      margin-left: 20px;
      font-size: 14px;
      font-weight: 500;
      color: #f59A23;
      width: 70px;
      height: 30px;
      line-height: 30px;
      border: 1px solid #f59A23;
      border-radius: 20px;
      text-align: center;
    }
  }
  .conentView{
    &-item{
      display: flex;
      margin-bottom: 15px;
      font-size: 15px;
      &-label{
        width: 80px;
        text-align: right;
        margin-right: 10px;
      }
    }
  }
  .bottomView{
    margin-top: 20px;
    display: flex;
  }
</style>
